Repository navigation
tls: initialize session and SNI before connecting - #65624
Merged
Merged
Conversation
Collaborator
|
Review requested:
|
styfle
force-pushed
the
styfle/tls-sync-lookup
branch
from
August 28, 2026 17:30
5f0fe2b to
737a73d
Compare
A synchronous custom lookup can abort the socket before tls.connect() applies the session and SNI, leaving the TLS handle unavailable. Initialize both before starting the connection so the original socket error is emitted normally. Assisted-by: Codex Signed-off-by: Steven <steven@ceriously.com>
styfle
force-pushed
the
styfle/tls-sync-lookup
branch
from
August 28, 2026 17:31
737a73d to
24774cc
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65624 +/- ##
==========================================
- Coverage 90.07% 90.04% -0.04%
==========================================
Files 751 751
Lines 254921 254920 -1
Branches 48129 48124 -5
==========================================
- Hits 229627 229545 -82
- Misses 16479 16544 +65
- Partials 8815 8831 +16
🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
aduh95
approved these changes
Aug 28, 2026
pimterry
approved these changes
Aug 28, 2026
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Member
Author
|
I can't see the results of CI - is there a bug in my code or is this a flake? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
Member
|
cc @nodejs/build the build above started by automation does not contain a Resume CI link |
jasnell
approved these changes
Sep 10, 2026
This comment was marked as outdated.
This comment was marked as outdated.
Collaborator
Collaborator
Collaborator
|
Landed in 9827749 |
aduh95
pushed a commit
that referenced
this pull request
Sep 27, 2026
A synchronous custom lookup can abort the socket before tls.connect() applies the session and SNI, leaving the TLS handle unavailable. Initialize both before starting the connection so the original socket error is emitted normally. Assisted-by: Codex Signed-off-by: Steven <steven@ceriously.com> PR-URL: #65624 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
HoonDongKang
pushed a commit
to HoonDongKang/node
that referenced
this pull request
Sep 28, 2026
A synchronous custom lookup can abort the socket before tls.connect() applies the session and SNI, leaving the TLS handle unavailable. Initialize both before starting the connection so the original socket error is emitted normally. Assisted-by: Codex Signed-off-by: Steven <steven@ceriously.com> PR-URL: nodejs#65624 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
aduh95
pushed a commit
that referenced
this pull request
Sep 28, 2026
A synchronous custom lookup can abort the socket before tls.connect() applies the session and SNI, leaving the TLS handle unavailable. Initialize both before starting the connection so the original socket error is emitted normally. Assisted-by: Codex Signed-off-by: Steven <steven@ceriously.com> PR-URL: #65624 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
thc1006
added a commit
to thc1006/sch001-108platform
that referenced
this pull request
Oct 27, 2026
本機跑全站 --record 時整支程式崩潰過一次:Unhandled 'error' event,Error: connect ENETUNREACH <IPv6 位址>:443。本機沒有 IPv6 的預設路由,connect 對外部 IPv6 位址當下就回 ENETUNREACH。 原因:requestOnce 傳給 https.request 的 lookup 同步呼叫 cb。net 在 lookup 的回呼裡直接連線, 每個位址都同步失敗時(只有一個位址走 internalConnect,多個位址走 internalConnectMultiple), socket 在 tls.connect 回傳前就被 destroy、_handle 變成 null,tls.connect 接著呼叫 setServername 丟出 TypeError。這個 TypeError 被 requestOnce 的 try/catch 接住,回傳 EREQUEST; 但 socket 已經排好下一個 tick 要發出的 error 事件,https.request 沒有回傳 ClientRequest,沒有人 掛 error 監聽,程式就此結束。只要還有一個位址是非同步失敗或連得上,例如 IPv6 加 IPv4,就不會發生, 所以重跑通常正常。http 不經過 tls.connect,同樣情況會照常回報 req 的 error。 重現(2001:db8::/32 是文件用位址,本機沒有路由):lookup 同步回傳 [2001:db8::1] 或 [2001:db8::1, 2001:db8::2],用 requestOnce 的選項呼叫 https.request,Node 24.21.0 與 24.22.1 都先丟 TypeError: Cannot read properties of null (reading 'setServername'),接著因為 Unhandled 'error' event 結束,單一位址是 ENETUNREACH,兩個位址是 AggregateError [ENETUNREACH]。 [2001:db8::1, 127.0.0.1] 不會。26.12.1 不會。 Node 的修正是 nodejs/node#65624(tls: initialize session and SNI before connecting), 2026-09-25 合併,收在 v26.11.0,v24.x 到 24.22.1 都還沒有。PR 的說明附了同一段錯誤訊息。 nodejs/node#48771 是 http 的同一類問題,nodejs/node#61658(v24.14.0)與 #61770(v24.15.0) 修了 http,tls 這條路徑到 #65624 才修。 修法:lookup 用 setImmediate 回呼,跟 dns.lookup 一樣非同步。連線失敗發生在 tls.connect 回傳、 ClientRequest 掛好 socket 的 error 處理之後,錯誤照一般連線失敗回到 req 的 error。上面的重現改成 非同步回呼之後,三種位址組合在 24.21.0 都回到 req 的 error。 link-health.test.mjs 加 2 條:https 的請求在每個位址都同步連線失敗時,probe 回傳 status 0、 ERR_IP_BLOCKED,不崩潰。同步失敗用 net.BlockList 製造,不看機器有沒有 IPv6 路由;一條只有一個 位址,一條兩個位址走 Happy Eyeballs。對上一個 commit 跑,兩條都失敗(code 是 EREQUEST,並觸發 uncaughtException)。link-health.faults.mjs 的 B 段加 1 項,把 lookup 改回同步回呼,擋下來。 Refs: nodejs/node#65624 Refs: nodejs/node#48771
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A synchronous custom lookup callback can cause the connection to fail or abort before
tls.connect()applies the TLS session and SNI. The failure clears the TLS handle, causingsetServername()to throw a synchronousTypeError.The original failure surfaced through an HTTP client as:
Initialize the session and SNI before starting the underlying TCP connection so the original connection error is emitted normally.